package com.ddxz.hetong.controller;

import com.ddxz.hetong.service.ElectricityService;
import com.ddxz.tool.web.dto.DdxzResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * description
 *
 * @author 朱宗刚
 * @version 1.0.0
 * @date 2022/7/28
 */

@RestController
@Api("电力接口")
@RequestMapping("/unity/electricity")
public class ElectricityController {
    @RequestMapping(value = "/all/import", method = RequestMethod.GET)
    @ApiOperation(value = "全部收入", consumes = "application/json", produces = "application/json",
            notes = "type: 1 年度指标；2 月度指标")
    public DdxzResponse getAllImport(@RequestParam(name = "year", required = false) Integer year,
                                     @RequestParam(name = "month", required = false) Integer month,
                                     @RequestParam(name = "factory", required = false) String factory,
                                     @RequestParam(name = "type") Integer type) {
        return service.getAllImport(year, month, factory, type);
    }

    @RequestMapping(value = "/detail", method = RequestMethod.GET)
    @ApiOperation(value = "详细信息", consumes = "application/json", produces = "application/json",
            notes = "有效的names取值如下：主营收入、其他业务收入、燃料成本、税金及附加、材料费、外购电费、外购水费、人工成本、" +
                    "外部劳务费、折旧摊销、修理费、七项费用、其他成本、其他业务成本、财务费用、减值。" +
                    "type: 1 年度指标；2 月度指标")
    public DdxzResponse getDetail(@RequestParam(name = "year", required = false) Integer year,
                                  @RequestParam(name = "month", required = false) Integer month,
                                  @RequestParam(name = "factory", required = false) String factory,
                                  @RequestParam(name = "names", required = false) List<String> name,
                                  @RequestParam(name = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                  @RequestParam(name = "pageNum", required = false, defaultValue = "1") Integer pageNum) {
        return service.getdetail(year, month, factory, name, pageNum, pageSize);
    }
    
    @RequestMapping(value = "/statistic", method = RequestMethod.GET)
    @ApiOperation(value = "汇总统计信息", consumes = "application/json", produces = "application/json",
            notes = "有效的names取值如下：主营收入、其他业务收入、燃料成本、税金及附加、材料费、外购电费、外购水费、人工成本、" +
                    "外部劳务费、折旧摊销、修理费、七项费用、其他成本、其他业务成本、财务费用、减值。" +
                    "type: 1-年度总指标；2-月度总指标，3-年度分指标，4-月度分指标")
    public DdxzResponse getStatistic(@RequestParam(name = "year", required = false) Integer year,
                                     @RequestParam(name = "month", required = false) Integer month,
                                     @RequestParam(name = "factory", required = false) String factory,
                                     @RequestParam(name = "names", required = false) List<String> name,
                                     @RequestParam(name = "type") Integer type) {
        return service.getStatistic(year, month, factory, name, type);
    }

    @RequestMapping(value = "/all/cost", method = RequestMethod.GET)
    @ApiOperation(value = "全部成本", consumes = "application/json", produces = "application/json",
            notes = "type: 1-年度总指标；2-月度总指标，3-年度分指标，4-月度分指标")
    public DdxzResponse getAllCost(@RequestParam(name = "year", required = false) Integer year,
                                   @RequestParam(name = "month", required = false) Integer month,
                                   @RequestParam(name = "factory", required = false) String factory,
                                   @RequestParam(name = "type") Integer type) {
        return service.getAllCost(year, month, factory, type);
    }

    @RequestMapping(value = "/except/cost", method = RequestMethod.GET)
    @ApiOperation(value = "燃料成本之外成本", consumes = "application/json", produces = "application/json",
            notes = "type: 1-年度总指标；2-月度总指标，3-年度分指标，4-月度分指标")
    public DdxzResponse getExceptCost(@RequestParam(name = "year", required = false) Integer year,
                                      @RequestParam(name = "month", required = false) Integer month,
                                      @RequestParam(name = "factory", required = false) String factory,
                                      @RequestParam(name = "type") Integer type) {
        return service.getExceptCost(year, month, factory, type);
    }

    @RequestMapping(value = "/import/file", method = RequestMethod.POST)
    @ApiOperation(value = "导入成本/利润数据", consumes = "application/json", produces = "application/json",
            notes = "type=1 导入成本/利润数据； <br />type=2 导入其他数据")
    public DdxzResponse importFile(MultipartFile file,
                                   @RequestParam Integer year,
                                   @RequestParam(name = "type", required = false, defaultValue = "1") Integer type) {
        return service.importExcel(file, year, type);
    }

    @RequestMapping(value = "/compare", method = RequestMethod.GET)
    @ApiOperation(value = "累计与装机容量对比", consumes = "application/json", produces = "application/json")
    public DdxzResponse compare(@RequestParam(name = "year", required = false) Integer year,
                                @RequestParam(name = "type") Integer type) {
        return service.compare(year, type);
    }

    @RequestMapping(value = "/history", method = RequestMethod.GET)
    @ApiOperation(value = "历年财务指标", consumes = "application/json", produces = "application/json",
            notes = "type取值如下：1-阶段统计，2 分年统计，3 全量汇总；<br /> " +
                    "stage取值如下： 1 建设期， 2 全容量投产，3 区域化管理，4 全部")
    public DdxzResponse history(@RequestParam(name = "year", required = false) Integer year,
                                @RequestParam(name = "type") Integer type,
                                @RequestParam(name = "stage", required = false) Integer stage) {
        return service.history(year, type, stage);
    }

    @RequestMapping(value = "/profitability", method = RequestMethod.GET)
    @ApiOperation(value = "查看盈利能力", consumes = "application/json", produces = "application/json",
            notes = "type = 1 年度， 2 月度, 年度是指定年度下的盈利能力；月度是指定年度下个月的盈利能力")
    public DdxzResponse profitability(@RequestParam(name = "type") Integer type,
                                      @RequestParam(name = "year", required = false) Integer year) {
        return service.profitability(type, year);
    }

    @RequestMapping(value = "/solvency", method = RequestMethod.GET)
    @ApiOperation(value = "查看偿债能力", consumes = "application/json", produces = "application/json",
            notes = "type = 1 年度， 2 月度, 年度是指定年度下的偿债能力；月度是指定年度下个月的偿债能力")
    public DdxzResponse solvency(@RequestParam(name = "type") Integer type,
                                 @RequestParam(name = "year", required = false) Integer year) {
        return service.solvency(type, year);
    }

    @RequestMapping(value = "/earning", method = RequestMethod.GET)
    @ApiOperation(value = "查看获利能力", consumes = "application/json", produces = "application/json",
            notes = "type = 1 年度， 2 月度, 年度是指定年度下的获利能力；月度是指定年度下个月的获利能力")
    public DdxzResponse earning(@RequestParam(name = "type") Integer type,
                                @RequestParam(name = "year", required = false) Integer year) {
        return service.earning(type, year);
    }

    @RequestMapping(value = "/profit", method = RequestMethod.GET)
    @ApiOperation(value = "查看利润分布", consumes = "application/json", produces = "application/json",
            notes = "type = 1 年度， 2 月度, 年度是指定年度下的利润分布；月度是指定年度下个月的利润分布")
    public DdxzResponse profit(@RequestParam(name = "type") Integer type,
                                @RequestParam(name = "year", required = false) Integer year) {
        return service.profit(type, year);
    }

    @RequestMapping(value = "/download", method = RequestMethod.GET)
    @ApiOperation(value = "下载模板", notes = "type=1 下载成本/利润模板;<br /> type=2 下载能力指标模板")
    public void downloadTemplate(@RequestParam(name = "type") Integer type, HttpServletResponse response) {
        service.downloadTemplate(type, response);
    }

    @RequestMapping(value = "/cost/top5", method = RequestMethod.GET)
    @ApiOperation(value = "除燃料成本之外成本Top5", consumes = "application/json", produces = "application/json")
    public DdxzResponse costTop5(@RequestParam(name = "year") Integer year) {
        return service.costTop5(year);
    }

    private final ElectricityService service;

    public ElectricityController(ElectricityService service) {
        this.service = service;
    }
}
